package com.dy.service.impl;

import com.dy.domain.Shangpin;
import com.dy.domain.Tu;
import com.dy.domain.pojo.PageBean;
import com.dy.mapper.ShangpinMapper;
import com.dy.service.ShangpinService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ShangpinServiceImpl implements ShangpinService {

    @Autowired
    private ShangpinMapper shangpinMapper;

    //分页查询所有 模糊
    @Override
    public PageBean<Shangpin> findPage(Integer pageNo, Integer pageSize, String ming) {

        PageHelper.startPage(pageNo,pageSize);

        List<Shangpin> list = shangpinMapper.mohu(ming);

        PageInfo<Shangpin> info = new PageInfo<>(list);

        PageBean<Shangpin> pageBean = new PageBean<>();

        pageBean.setPageCount(info.getPages());
        pageBean.setTotalCount(info.getTotal());
        pageBean.setObject(info.getList());

        return pageBean;
    }

    @Override
    public void add(Shangpin shangpin) {
        shangpinMapper.add(shangpin);
    }

    @Override
    public Shangpin huixian(Integer sid) {
       return shangpinMapper.huixian(sid);
    }

    @Override
    public void update(Shangpin shangpin) {
        shangpinMapper.update(shangpin);
    }

    @Override
    public void del(Integer sid) {

        shangpinMapper.del(sid);
    }

    @Override
    public List<Shangpin> findall() {
        return shangpinMapper.findall();
    }

    @Override
    public List<Tu> find() {
        return shangpinMapper.find();
    }
}
